CPU 686
BITS 32

%define DATA_REG 0x60
%define EOI 0x20
%define PIC1_CMD 0x20
%define PIC2_CMD 0xA0

global _mouse_isr

global _mouse
global _num_byte
global _pack_completo

;-----------------------------------------------

section .data

_mouse db 0, 0, 0
_num_byte dd 1
_pack_completo dd 0


;-----------------------------------------------

section .text

_mouse_isr:

	push eax
	push ecx
	push ebx
	
;-----------------------
	
	xor eax, eax ;coloca o EAX a zero
	in al, DATA_REG
	
	mov ecx, dword[_num_byte]
	
	cmp ecx, 3
	je byte3
	cmp ecx, 2
	je byte2
	
byte1:
	mov byte[_mouse], al
	mov ecx, 2
	jmp fim

byte2:
	mov byte[_mouse + 1], al
	mov ecx, 3
	jmp fim
	
byte3:
	mov byte[_mouse + 2], al
	mov ebx , 1 
	mov dword[_pack_completo], ebx
	mov ecx, 1

fim:
	mov dword[_num_byte], ecx

;-----------------------
	
	mov al, EOI
	out PIC1_CMD, al
	out PIC2_CMD, al

	pop ebx
	pop ecx
	pop eax
	iretd
END
